package xstrings

import (
	"strconv"
	"strings"

	"github.com/sirupsen/logrus"
)

func IsBlank(str string) bool {

	return strings.TrimSpace(str) == ""
}

func ConvStrToInt(str string) int {
	num, err := strconv.Atoi(str)
	if err != nil {
		logrus.Errorf("convertStrToInt error: %v %v", str, err)
	}
	return num
}

func ConvStrToIntQuiet(str string) int {
	num, _ := strconv.Atoi(str)

	return num
}

func ConvStrToFloat(str string) float64 {
	num, err := strconv.ParseFloat(str, 64)
	if err != nil {
		logrus.Errorf("ConvertStrToFloat error: %v %v", str, err)
	}
	return num
}

func ConvStrToFloatQuiet(str string) float64 {
	num, _ := strconv.ParseFloat(str, 64)

	return num
}

func IsNumeric(str string) bool {
	_, err := strconv.Atoi(str)
	if err == nil {
		return true
	}

	_, err = strconv.ParseFloat(str, 64)

	return err == nil
}
